window.onload = function() {
	var APP_ID = 'eG22PNfwqck3fDTem41ACiNU-gzGzoHsz';
	var APP_KEY = 'Y8VoXz0cIzsJVbpctUAJXAAh';
	AV.init({
		appId: APP_ID,
		appKey: APP_KEY
	});
	pddenglu();
	var currentUser = AV.User.current();
	updateProduct1();
	updateProduct2();
	updateProduct3();
	updateProduct4();
}

function pddenglu() {
	currentUser = AV.User.current();
	href = "denglu.html?RetUrl=" + getPageUrl() + "&" + geturl();
	$(".top_a ul li").eq(1).html("<a href=" + href + ">登录</a>")
	if (currentUser) {
		$(".top_a ul li").eq(0).html("欢迎【" + currentUser.attributes.username + "】|");
		$(".top_a ul li").eq(1).html("<a>退出登录</a>");
		$(".top_a ul li").eq(1).bind("click", function() {
			localStorage.clear();
			location.href = location.href;
		})
	}
}

function getPageUrl() {
	var index = location.pathname.lastIndexOf("/") + 1;
	var i = location.pathname.substr(index);
	//			console.log(i)
	return escape(i)
}

function geturl() {
	var u = location.search;
	u = u.substring(1, (u.length))
	console.log(u);
	return u;
}

function updateProduct1() {
	// LeanCloud - 查询
	// https://leancloud.cn/docs/leanstorage_guide-js.html#查询
	var query = new AV.Query('Chinese_Painting');
	query.descending('createdAt');
	query.find().then(function(products) {
		for (var i = 0; i < 6; i++) {
			var divtj = '<div class="meiri_right_div1"><a href="ComDet.html?biao=Chinese_Painting&id=' + products[i].attributes.inid + '">';
			divtj += '<img src="' + products[i].attributes.image[0] + '">';
			divtj += '<p><span>' + products[i].attributes.title + '</span><br/><span>￥' + products[i].attributes.price + '00</span></P>';
			divtj += '</a></div>';
			$("#shuhua").append(divtj);
		}
		// 查询到商品后，在前端展示到相应的位置中

	}).catch(function(error) {
		alert(JSON.stringify(error));
	});
}

function updateProduct2() {
	// LeanCloud - 查询
	// https://leancloud.cn/docs/leanstorage_guide-js.html#查询
	var query = new AV.Query('Ancient_Porcelai');
	query.descending('createdAt');
	query.find().then(function(products) {
		for (var i = 0; i < 6; i++) {
			var divtj = '<div class="meiri_right_div1"><a href="ComDet.html?biao=Ancient_Porcelai&id=' + products[i].attributes.inid + '">';
			divtj += '<img src="' + products[i].attributes.image[0] + '">';
			divtj += '<p><span>' + products[i].attributes.title + '</span><br/><span>￥' + products[i].attributes.price + '00</span></P>';
			divtj += '</a></div>';
			$("#tongqi").append(divtj);
		}
		// 查询到商品后，在前端展示到相应的位置中

	}).catch(function(error) {
		alert(JSON.stringify(error));
	});
}

function updateProduct3() {
	// LeanCloud - 查询
	// https://leancloud.cn/docs/leanstorage_guide-js.html#查询
	var query = new AV.Query('Contemporary_Crafts');
	query.descending('createdAt');
	query.find().then(function(products) {
		for (var i = 0; i < 6; i++) {
			var divtj = '<div class="meiri_right_div1"><a href="ComDet.html?biao=Contemporary_Crafts&id=' + products[i].attributes.inid + '">';
			divtj += '<img src="' + products[i].attributes.image[0] + '">';
			divtj += '<p><span>' + products[i].attributes.title + '</span><br/><span>￥' + products[i].attributes.price + '00</span></P>';
			divtj += '</a></div>';
			$("#ciqi").append(divtj);
		}
		// 查询到商品后，在前端展示到相应的位置中

	}).catch(function(error) {
		alert(JSON.stringify(error));
	});
}

function updateProduct4() {
	// LeanCloud - 查询
	// https://leancloud.cn/docs/leanstorage_guide-js.html#查询
	var query = new AV.Query('Canvas');
	query.descending('createdAt');
	query.find().then(function(products) {
		for (var i = 0; i < 6; i++) {
			var divtj = '<div class="meiri_right_div1"><a href="ComDet.html?biao=Canvas&id=' + products[i].attributes.inid + '">';
			divtj += '<img src="' + products[i].attributes.image[0] + '">';
			divtj += '<p><span>' + products[i].attributes.title + '</span><br/><span>￥' + products[i].attributes.price + '00</span></P>';
			divtj += '</a></div>';
			$("#mudiao").append(divtj);
		}
		// 查询到商品后，在前端展示到相应的位置中

	}).catch(function(error) {
		alert(JSON.stringify(error));
	});
}